package cn.kgc.springboot.controller;

import cn.kgc.springboot.entity.User;
import cn.kgc.springboot.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 课工场
 * @date 2024/11/28
 * @description
 * localhost:8080/springboot/hello/m1
 */
@Controller
@RequestMapping("hello")
public class HelloController {


    @Autowired
    private HelloService helloService;


    @GetMapping("m1")
    @ResponseBody
    public Map<String,Object> method1(){

        HashMap<String, Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","hello springboot");

        return result;

    }

    @GetMapping("m2")
    public String method2(){
        return "hello3";  // 视图名

    }

    @GetMapping("m3")
    @ResponseBody
    public List<User> method3(){

        List<User> users = helloService.userList();
        return users;
    }

    @GetMapping("m4/{id}")
    @ResponseBody
    public Map<String,Object> method4(@PathVariable("id") Integer id){

       return helloService.deleteUser(id);

    }

}
